package vm
{
	import data.Opcode;
	
	import kinds.OpcodeKind;
	
	import struct.Stack;

	public class Vm
	{
		/** 本地寄存器*/
		private var _local:Array = null;
		
		/** 栈*/
		private var _stack:Stack = null;
		
		public function Vm()
		{
			_stack = new Stack();
			_local = new Array();
		}
		
		public function execute(opcodes:Array):void
		{
			var sp:int = 0;
			var opcode:Opcode = null;
			while(true){
				if(!opcodes.hasOwnProperty(sp) || opcodes[sp] == null){
					trace("程序非正常退出！！！");
					break;
				}
				opcode = opcodes[sp];
				switch(opcode.flag){
					case OpcodeKind.OP_getlocal0:
						_stack.push("this");
						break;
					case OpcodeKind.OP_popscope:
						_stack.push("scope");
						break;
					case OpcodeKind.OP_construct:
						_stack.pop();
						break;
				}
			}
		}
		
	}
}